package com.example.myblog.common;

import lombok.Builder;
import lombok.Data;

/*
    统一数据返回格式
 */
@Builder //建造者模式
@Data
public class AjaxResult {
    private Integer code;//状态码
    private String msg;//状态码描述信息
    private Object data;//数据

    /*
        操作成功的返回数据封装
     */
    public static AjaxResult success(Object data) {
        return AjaxResult.builder().code(200).msg("操作成功").data(data).build();
    }

    public static AjaxResult success(Integer code, Object data) {
        return AjaxResult.builder().code(code).msg("操作成功").data(data).build();
    }

    public static AjaxResult success(Integer code, String msg, Object data) {
        return AjaxResult.builder().code(code).msg(msg).data(data).build();
    }

    /*
        操作失败的返回数据封装
     */
    public static AjaxResult fail(Integer code, String msg) {
        return AjaxResult.builder().code(code).msg(msg).build();
    }

    public static AjaxResult fail(Integer code, String msg, Object data) {
        return AjaxResult.builder().code(code).msg(msg).data(data).build();
    }
}
